<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>门店切换时间</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<script type="text/javascript" src="${layerPath}/jquery/jquery-1.8.3.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="${csspath }/datepicker.css"/>
<script type="text/javascript" src="${jspath }/ui.datepicker_zh-CN.js"></script>
<script type="text/javascript" src="${jspath }/jquery.ui.min.js"></script>
<script type="text/javascript"
	src="${bootstrapPath}/js/bootstrap3-validation.js"></script>
	
<script type="text/javascript">
function closeLayer(){
	//当你在iframe页面关闭自身时
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	parent.layer.close(index); //再执行关闭  	
}

function saveChange(o,p){
	if($.trim($("#"+ p).val()) == ""){
		jAlert("切换日期不能为空！","提示信息");
		return;
	}
	$.ajax({
		url : "${webcontext}/crmdp/dealer/masterdata/updateDealerChange?dealerNum="+ encodeURI(encodeURI(o)) + "&changeDate="+ encodeURI(encodeURI($("#"+ p).val())),
		type : 'post',
		success : function(data) {
			if(data == true){
				jAlert("修改成功","提示信息");
			}else{
				jAlert("修改失败","提示信息");
			}
		}
	});
}

//验证输入的内容只为数字
function isNum(num){
	var reNum=/^\d*$/;
	return(reNum.test(num));
	}

$(function(){
	$("#saveAndSubmit").click(function(){
		if($.trim($("#dealerNum").val()) == "" || $.trim($("#dealerName").val()) == "" || $.trim($("#changeDate").val()) == ""){
			jAlert("所有需填写内容均不能为空！","提示信息");
			return;
		}else if(!isNum($("#dealerNum").val())){
			jAlert("门店号必须为数字！","提示信息");
		}else{
			$.ajax({
				type : 'POST',
				url : '${webcontext}/crmdp/dealer/masterdata/checkDealerExisted',
				async : false,
				data : $(
						'#addDealerChange')
						.serialize(),
				dataType : 'json',
				success : function(data) {
					if(data){
						jAlert("该记录已添加过,不可重复添加","提示信息");
					}else{
						$.ajax({
							type : 'POST',
							url : '${webcontext}/crmdp/dealer/masterdata/saveDealerChanged',
							async : false,
							data : $(
									'#addDealerChange')
									.serialize(),
							dataType : 'json',
							success : function(data) {
								if(data){
									jAlert("添加成功","提示信息",function(result){
										parent.location.href = "${webcontext}/crmdp/dealer/masterdata/toDealerChange";
									});
								}else{
									jAlert("添加失败","提示信息");
								}
							}
						});
					}
				}
			});	
		}
	});
});
</script>
</head>
<style>
.form-control1 {
	width: 100%;
	height: 34px;
	padding: 6px 12px;
	font-size: 14px;
	line-height: 1.42857;
	color: #555;
	background-color: #FFF;
	background-image: none;
	border: 1px solid #CCC;
	border-radius: 0px;
	box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
	transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s
		ease-in-out 0s;
}
</style>
<body>
	<div class="main" style="margin: 10px;margin-left: 70px;">
		<form:form class="form-horizontal" id="addDealerChange" method="post"
			action="" role="form"
			enctype="multipart/form-data">
			<div style="margin-left: 40px;">
			<div class="form-group">
				<label for="dealerNum" class="col-sm-2 control-label">门店号</label>
				<div class="col-sm-3">
					<input type="text" class="form-control input-sm" id="dealerNum"
						name="dealerNum" style="width: 150px;"/>
				</div>
			</div>
			<div class="form-group">
				<label for="dealerName" class="col-sm-2 control-label">店名</label>
				<div class="col-sm-3">
					<input type="text" class="form-control input-sm" id="dealerName"
						name="dealerName" style="width: 150px;"/>
				</div>
			</div>
			<div class="form-group">
				<label for="changeDate" class="col-sm-2 control-label">切换日期</label>
				<div class="col-sm-3">
					<input type="text" class="form-control input-sm date" id="changeDate"
						name="changeDate" style="width: 150px;"/>
				</div>
			</div>
			</div>
			<div class="form-group text-center" style="margin-left: -100px;">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="btn btn-success" id="saveAndSubmit">
						<i class="glyphicon glyphicon-ok" style="color: #FFFFFF"></i>保存
					</button>
					<button type="button" class="btn btn-success"
						onClick="closeLayer()">
						<i class="glyphicon glyphicon-share-alt" style="color: #FFFFFF"></i>取消
					</button>
				</div>
			</div>
		</form:form>
	</div>
</body>
</html>